package cn.stylefeng.guns.modular.task.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.task.entity.TaskOrder;
import cn.stylefeng.guns.modular.task.mapper.TaskOrderMapper;
import cn.stylefeng.guns.modular.task.model.params.TaskOrderParam;
import cn.stylefeng.guns.modular.task.model.result.TaskOrderResult;
import  cn.stylefeng.guns.modular.task.service.TaskOrderService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 作业单表 服务实现类
 */
@Service
public class TaskOrderServiceImpl extends ServiceImpl<TaskOrderMapper, TaskOrder> implements TaskOrderService {

    @Override
    public void add(TaskOrderParam param){
        TaskOrder entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaskOrderParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaskOrderParam param){
        TaskOrder oldEntity = getOldEntity(param);
        TaskOrder newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaskOrderResult findBySpec(TaskOrderParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<TaskOrderResult> findListBySpec(TaskOrderParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaskOrderParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo findPageBySpecApplets(TaskOrderParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageListApplets(pageContext, param,condition,operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaskOrderParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaskOrder getOldEntity(TaskOrderParam param) {
        return this.getById(getKey(param));
    }

    private TaskOrder getEntity(TaskOrderParam param) {
        TaskOrder entity = new TaskOrder();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public int countBydate(TaskOrderParam param,Long operateId) {
		Integer a;
		a = this.baseMapper.countBydate(param,operateId);
		if (a == null) {
			return 0;
		}
		return a;
	}

	@Override
	public List<TaskOrderResult> findtaskreportList(TaskOrderParam param,Long operateId) {
		return this.baseMapper.findtaskreportList(param,operateId);
	}

	@Override
	public List<TaskOrderResult> operateTaskList(TaskOrderParam param, String condition,Long operateId) {
		return this.baseMapper.operateTaskList(param,condition, operateId);
	}

	@Override
	public List<TaskOrderResult> operateTaskSum(TaskOrderParam param, String condition,Long operateId) {
		return this.baseMapper.operateTaskSum(param,condition, operateId);
	}

	@Override
	public List<TaskOrderResult> panelOperateDay(TaskOrderParam param) {
		return this.baseMapper.panelOperateDay(param);
	}

	@Override
	public List<TaskOrderResult> panelOperateMonth(TaskOrderParam param) {
		return this.baseMapper.panelOperateMonth(param);
	}

	@Override
	public TaskOrderResult findSum(TaskOrderParam param) {
		return this.baseMapper.findSum(param);
	}

	@Override
	public TaskOrderResult findSum2(TaskOrderParam param) {
		return this.baseMapper.findSum2(param);
	}

	@Override
	public TaskOrderResult findCount(TaskOrderParam param) {
		return this.baseMapper.findCount(param);
	}

	@Override
	public List<TaskOrderResult> findSumtaskWork(TaskOrderParam param) {
		return this.baseMapper.findSumtaskWork(param);
	}

	@Override
	public List<TaskOrderResult> panelOperateMonthDuibi(TaskOrderParam param) {
		return this.baseMapper.panelOperateMonthDuibi(param);
	}


}
